package com.tarena.lbs.activity.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tarena.lbs.activity.dao.mapper.ActivityMapper;
import com.tarena.lbs.activity.dao.repository.ActivityRepository;
import com.tarena.lbs.activity.pojo.po.ActivityPO;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
/**
 * @author 周恒宇
 * @date 6/10
 */
@Slf4j
@Repository
public class ActivityRepositoryImpl implements ActivityRepository {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageInfo<ActivityPO> pageList() {
        log.info("活动列表仓储层");
        QueryWrapper<ActivityPO> queryWrapper = new QueryWrapper<>();
        PageHelper.startPage(1, 10);
        List<ActivityPO> list = activityMapper.selectList(queryWrapper);
        return new PageInfo<>(list);
    }

    @Override
    public void activitySave(ActivityPO activityPO) {
        if(activityPO.getId()==null){
            log.info("活动保存仓储层");
            activityMapper.insert(activityPO);
        }else{
            log.info("活动更新仓储层");
            activityMapper.updateById(activityPO);
        }

    }

    @Override
    public ActivityPO selectById(Integer id) {
        ActivityPO activityPO= activityMapper.selectById(id);
        return activityPO;
    }




}
